/**
 * Created by Peter on 2016/4/27.
 */
define(['jquery'], function ($) {
    return {
        toggleWidgetLoading: function (wgt, states) {
            var $this = wgt;
            if (typeof wgt == "string") {
                $this = $('#' + wgt);
            }

            var header = $this.find('header');
            var content = $this.find('div[role=content]');

            if (states == true || states == "true" || states == "reset") {
                header.removeClass('widget-body-ajax-loading');
                content.removeClass('widget-body-ajax-loading');
                return;
            } else if (states == false || states == "false" || states == "loading") {
                header.addClass('widget-body-ajax-loading');
                content.addClass('widget-body-ajax-loading');
                return;
            }

            if (header.hasClass('widget-body-ajax-loading')) {
                header.removeClass('widget-body-ajax-loading');
                content.removeClass('widget-body-ajax-loading');
            } else {
                header.addClass('widget-body-ajax-loading');
                content.addClass('widget-body-ajax-loading');
            }
        },
        toggleGridLoading: function (wgt, states) {
            var $this = wgt;
            if (typeof wgt == "string") {
                $this = $('#' + wgt);
            }

            if (states == true || states == "true" || states == "reset") {
                $this.removeClass('widget-body-ajax-loading');
                return;
            } else if (states == false || states == "false" || states == "loading") {
                $this.addClass('widget-body-ajax-loading');
                return;
            }
        }
    }
});